package Demo;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class BallFrame extends JFrame{
	private BallPanel panel;
	public static final int DEFAULT_WIDTH = 450;
	public static final int DEFAULT_HEIGHT = 350;
	int count=1;
	public BallFrame(){
	setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
	setTitle("CreatBall");
	panel = new BallPanel();
	add(panel , BorderLayout.CENTER);
	JPanel buttonPanel = new JPanel();
	buttonPanel.setBackground(Color.gray); 
	addButton(buttonPanel, "Add_Ball",
		new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				addBall();
				//System.out.println(count++);
				}
			}
		); 
		add(buttonPanel, BorderLayout.SOUTH);
	}
	public void addButton(Container c, String title, ActionListener listener){
		JButton bt = new JButton(title);
		c.add(bt);
		bt.addActionListener(listener);
	}
	public void addBall(){
		Ball b = new Ball();
		panel.add(b);
		Runnable r = new BallRunnable(b, panel);
		Thread t = new Thread(r);
		t.start();
	}
}
